﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page
{
    clsUser ObjUser = new clsUser();
    protected void Page_Load(object sender, EventArgs e)
    {

    }
     
    protected void  btnSendPassword_Click(object sender, EventArgs e)
{
        ObjUser.Email = txtEmailForForgetPassword.Text.Trim();
        //ObjUser.PageCode = "UserForForgetPassword";
        SqlDataReader objDataReader = ObjUser.GetDetails("UserForForgetPassword", ObjUser.Email);
        if (objDataReader.HasRows)
        {
            objDataReader.Read();
            ObjUser.IsActive = Convert.ToBoolean(objDataReader["IsActive"]);
            ObjUser.Password = Convert.ToString(objDataReader["Password"]);
            if (ObjUser.Email == null)
            {
                litLoginMsg.Text = "Sorry no username exists with this email id";
                return;
            }
            if (ObjUser.IsActive == false)
            {
                litLoginMsg.Text = "User email address is inactive,Please contact the administrator to activate your account";
                return;
            }
            if (ObjUser.Password != null && ObjUser.Password != "")
            {
                SendMail(SetForgotpasswordEmailParameters(ObjUser.Password), "ForgotPassword.htm", ObjUser.Email, "Forgot Password");
                txtEmailForForgetPassword.Text = string.Empty;
                //lblmsg3.Text = "An email has been sent. Please, check your email";
                //lblmsg3.Visible = true;
                //ModalPopupExtenderForgot.Show();
            }
        }
        else
        {
            litLoginMsg.Text = "Please  Provide Your Registered Email";
        }

}
    protected void SendMail(Hashtable KeysValues, string TemplateName, string emailAddress, string subject)
    {

        string Template = clsUser.ReadFileReturnHTML("EmailTemplates", TemplateName, KeysValues);
        CommonClass.SendEmail(subject, emailAddress, Template);

    }
    public Hashtable SetForgotpasswordEmailParameters(string password)
    {
        string Strlogolink = "", domaintype = "", domainnamelocal = "", domainnamelive = "", domainname = "";

        domainnamelive = ConfigClass.liveLink;
      

        if (domaintype.ToLower() == "local")
            domainname = domainnamelocal;
        else
            domainname = domainnamelive;
        Hashtable KeysValues = new Hashtable();
        string img = domainname + "/images/logo2.png";
        string bgimg = domainname + "/images/Makena,-Maui,-Hawaii3.jpg";
        KeysValues.Add("#headerImage#", bgimg);
        KeysValues.Add("#footerImagePath#", img);
        KeysValues.Add("#logolinkpath#", Strlogolink);
        KeysValues.Add("#loginid#", txtEmailForForgetPassword.Text.ToString().Trim());
        KeysValues.Add("#password#", password);
        KeysValues.Add("#logopath#", img);
        KeysValues.Add("#AdminEmailId#", ConfigClass.AdminEmailId);
        return KeysValues;
    }
}